home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / games / uchess / src / nondsp.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  22KB  |  994 lines

  1. /*
  2.  * nondsp.c - UNIX & MSDOS NON-DISPLAY, AND CHESSTOOL interface for Chess
  3.  *
  4.  * Copyright (c) 1988,1989,1990 John Stanback
  5.  * Copyright (c) 1992 Free Software Foundation
  6.  *
  7.  * This file is part of GNU CHESS.
  8.  *
  9.  * GNU Chess is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2, or (at your option)
  12.  * any later version.
  13.  *
  14.  * GNU Chess is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with GNU Chess; see the file COPYING.  If not, write to
  21.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23.  
  24. #include <ctype.h>
  25. #include <signal.h>
  26.  
  27. #ifdef AMIGA
  28. #define __USE_SYSBASE
  29. #include <exec/types.h>
  30. #include <exec/exec.h>
  31. #include <proto/exec.h>
  32. #include <proto/dos.h>
  33. #include <proto/graphics.h>
  34. #include <proto/intuition.h>
  35. #endif
  36.  
  37. char __far HintString[80];
  38.  
  39. #define SIGQUIT SIGINT
  40.  
  41. #include "gnuchess.h"
  42. #ifdef MSDOS
  43. #include <dos.h>
  44. #include <conio.h>
  45. #include <stdlib.h>
  46. #include <string.h>
  47. #include <time.h>
  48. #else
  49. #include <dos.h>
  50. #include <stdlib.h>
  51. #include <string.h>
  52. #include <time.h>
  53. /*
  54. #include <sys/param.h>
  55. #include <sys/types.h>
  56. #include <sys/file.h>
  57. #include <sys/ioctl.h>
  58. */
  59. #endif
  60.  
  61.  
  62. extern short int ISZERO;
  63. char __aligned __far IllegalString[40];
  64. extern int AmigaStarted;
  65. extern int __aligned global_tmp_score;
  66. extern int __aligned previous_score;
  67. int __aligned IllegalMove=0;
  68. int __aligned Mate=0;
  69. int __aligned DrawnGame=0;
  70. char __far __aligned MateString[40]={0};
  71. extern long OrigResponse;
  72.  
  73. #ifdef DEBUG
  74. INTSIZE int __aligned debuglevel = 0;
  75.  
  76. #endif /* DEBUG */
  77. unsigned INTSIZE int __aligned MV[MAXDEPTH];
  78. int __aligned MSCORE;
  79.  
  80. #if defined CHESSTOOL || defined XBOARD
  81. INTSIZE int __aligned chesstool = 1;
  82.  
  83. #else
  84. INTSIZE int __aligned chesstool = 0;
  85.  
  86. #endif /* CHESSTOOL */
  87. extern char mvstr[4][6];
  88. int __aligned mycnt1, mycnt2;
  89. char __aligned *DRAW;
  90. extern char *InPtr;
  91. extern INTSIZE int pscore[];
  92.  
  93. void
  94. Initialize (void)
  95. {
  96.   mycnt1 = mycnt2 = 0;
  97. #if defined CHESSTOOL || defined XBOARD
  98. #ifndef SYSV
  99. /*  setlinebuf (stdout);*/
  100. #else
  101. /*  setvbuf (stdout, NULL, _IOLBF, BUFSIZ);*/
  102. #endif
  103. /*  printf (CP[43]);*/        /*Chess*/
  104.   if (!TCflag && (MaxResponseTime == 0))
  105.     MaxResponseTime = 15L*100L;
  106. #endif /* CHESSTOOL */
  107. }
  108.  
  109.  
  110. void DoAMove(void);
  111.  
  112. void DoAMove()
  113. {
  114.  char astr[40];
  115.  int r,c,l;
  116.  char piece;
  117.  
  118.       r = mvstr[0][3] - '1';
  119.       c = mvstr[0][2] - 'a';
  120.       l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  121.       if (color[l] == neutral)
  122.        {
  123.     DisplayBeep(0L);
  124.         Delay(25L);
  125.     DisplayBeep(0L);
  126.         Delay(25L);
  127.     DisplayBeep(0L);
  128.         Delay(25L);
  129.         piece = ' ';
  130.        }
  131.       else if (color[l] == white)
  132.         piece = qxx[board[l]]; /* white are lower case pieces */
  133.       else
  134.         piece = pxx[board[l]]; /* black are upper case pieces */
  135.   if (computer == black)
  136.    sprintf(astr,"%d: %s",GameCnt>>1,mvstr[0]);
  137.   else
  138.    sprintf(astr,"%d: %s",(GameCnt+1)>>1,mvstr[0]);   
  139.   DisplayComputerMove(astr);
  140.   AnimateAmigaMove(mvstr[0],piece);
  141. }
  142. void
  143. ExitChess (void)
  144. {
  145. /*  signal (SIGTERM, SIG_IGN);*/
  146.   ListGame (0L);
  147. #ifdef AMIGA
  148.   if (AmigaStarted)
  149.    AmigaShutDown();
  150. #endif
  151.   exit (0);
  152. }
  153.  
  154. #ifndef MSDOS            /* never called!!! */
  155. #ifndef AMIGA
  156. void
  157. Die (int sig)
  158. {
  159.   char s[80];
  160.  
  161.   ShowMessage (CP[31]);        /*Abort?*/
  162.   scanz ("%s", s);
  163.   if (strcmp (s, CP[210]) == 0)    /*yes*/
  164.     ExitChess ();
  165. }
  166. #endif
  167. #endif /* MSDOS */
  168.  
  169. void
  170. TerminateSearch (int sig)
  171. {
  172. #ifdef MSDOS
  173.   sig++;            /* shut up the compiler */
  174. #endif /* MSDOS */
  175.   if (!flag.timeout)
  176.     flag.musttimeout = true;
  177.   flag.bothsides = false;
  178. }
  179.  
  180.  
  181. void
  182. help (void)
  183. {
  184. #ifndef AMIGA
  185.   ClrScreen ();
  186.   /*printz ("CHESS command summary\n");*/
  187.   printz (CP[40]);
  188.   printz ("----------------------------------------------------------------\n");
  189.   /*printz ("g1f3      move from g1 to f3      quit      Exit Chess\n");*/
  190.   printz (CP[158]);
  191.   /*printz ("Nf3       move knight to f3       beep      turn %s\n", (flag.beep) ? "off" : "on");*/
  192.   printz (CP[86], (flag.beep) ? CP[92] : CP[93]);
  193.   /*printz ("a7a8q     promote pawn to queen\n");*/
  194.   printz (CP[128], (flag.material) ? CP[92] : CP[93]);
  195.   /*printz ("o-o       castle king side        easy      turn %s\n", (flag.easy) ? "off" : "on");*/
  196.   printz (CP[173], (flag.easy) ? CP[92] : CP[93]);
  197.   /*printz ("o-o-o     castle queen side       hash      turn %s\n", (flag.hash) ? "off" : "on");*/
  198.   printz (CP[174], (flag.hash) ? CP[92] : CP[93]);
  199.   /*printz ("bd        redraw board            reverse   board display\n");*/
  200.   printz (CP[130]);
  201.   /*printz ("list      game to chess.lst       book      turn %s used %d of %d\n", (Book) ? "off" : "on", bookcount, BOOKSIZE);*/
  202.   printz (CP[170], (Book) ? CP[92] : CP[93], bookcount, BOOKSIZE);
  203.   /*printz ("undo      undo last ply           remove    take back a move\n");*/
  204.   printz (CP[200]);
  205.   /*printz ("edit      edit board              force     enter game moves\n");*/
  206.   printz (CP[153]);
  207.   /*printz ("switch    sides with computer     both      computer match\n");*/
  208.   printz (CP[194]);
  209.   /*printz ("white     computer plays white    black     computer plays black\n");*/
  210.   printz (CP[202]);
  211.   /*printz ("depth     set search depth        clock     set time control\n");*/
  212.   printz (CP[149]);
  213.   /*printz ("post      principle variation     hint      suggest a move\n");*/
  214.   printz (CP[177]);
  215.   /*printz ("save      game to file            get       game from file\n");*/
  216.   printz (CP[188]);
  217.   /*printz ("random    randomize play          new       start new game\n");*/
  218.   printz (CP[181]);
  219.   printz ("----------------------------------------------------------------\n");
  220.   /*printz ("Computer: %-12s Opponent:            %s\n",*/
  221.   printz (CP[46],
  222.       ColorStr[computer], ColorStr[opponent]);
  223.   /*printz ("Depth:    %-12d Response time:       %d sec\n",*/
  224.   printz (CP[51],
  225.       MaxSearchDepth, MaxResponseTime/100);
  226.   /*printz ("Random:   %-12s Easy mode:           %s\n",*/
  227.   printz (CP[99],
  228.       (dither) ? CP[93] : CP[92], (flag.easy) ? CP[93] : CP[92]);
  229.   /*printz ("Beep:     %-12s Transposition file: %s\n",*/
  230.   printz (CP[36],
  231.       (flag.beep) ? CP[93] : CP[92], (flag.hash) ? CP[93] : CP[92]);
  232.   /*printz ("Time Control %s %d moves %d seconds %d opr %d depth\n", (TCflag) ? "ON" : "OFF",*/
  233.   printz (CP[110], (TCflag) ? CP[93] : CP[92],
  234.       TimeControl.moves[white], TimeControl.clock[white] / 100, OperatorTime, MaxSearchDepth);
  235.   signal (SIGINT, TerminateSearch);
  236. #ifndef MSDOS
  237.   signal (SIGQUIT, TerminateSearch);
  238. #endif /* MSDOS */
  239. #endif
  240. }
  241.  
  242. void
  243. EditBoard (void)
  244.  
  245. /*
  246.  * Set up a board position. Pieces are entered by typing the piece followed
  247.  * by the location. For example, Nf3 will place a knight on square f3.
  248.  */
  249.  
  250. {
  251.   INTSIZE a, r, c, sq, i, found;
  252.   int tmpcolor;
  253.   char s[80];
  254.  
  255.   flag.regularstart = false;
  256.   Book = 0;
  257. #ifndef AMIGA
  258.   /*printz (".   exit to main\n");*/
  259.   printz (CP[29]);
  260.   /*printz ("#   clear board\n");*/
  261.   printz (CP[28]);
  262.   /*printz ("c   change sides\n");*/
  263.   printz (CP[136]);
  264.   /*printz ("enter piece & location: \n");*/
  265.   printz (CP[155]);
  266. #else
  267.   if (!OpenAmigaEditWindow())
  268.    { /* open the window which will give us back text string */
  269.     DisplayBeep(0L);
  270.     Delay(25L);
  271.     DisplayBeep(0L);
  272.     return;
  273.    }
  274. #endif
  275.  
  276.   a = tmpcolor = white;
  277.   do
  278.     {
  279.       GetEditText(s,&tmpcolor); /* amiga routine to get the command from user */
  280.       found=0;
  281.       if (s[0] == CP[28][0])    /*#*/
  282.     for (sq = 0; sq < 64; sq++)
  283.       {
  284.         board[sq] = no_piece;
  285.         color[sq] = neutral;
  286.       }
  287.       if (a != tmpcolor)    /*c*/
  288.     a = otherside[a];
  289.       c = s[1] - 'a';
  290.       r = s[2] - '1';
  291.       if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
  292.     {
  293.       sq = locn (r, c);
  294.       color[sq] = a;
  295.       board[sq] = no_piece;
  296.       for (i = no_piece; i <= king; i++)
  297.         if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
  298.           {
  299.         board[sq] = i;
  300.         found=1;
  301.         break;
  302.           }
  303.       if ((found==0)||(board[sq] == no_piece)) color[sq] = neutral;    
  304.     }
  305.   } while (s[0] !